package com.zjz.demo.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/10/09/11:15
 * @Description: 5个用户,筛选 1.Id为偶数, 2.年龄大于23岁 3,用户名转换为大写 4.用户名字字母倒着写 5,只输出一个用户
 * @Target:
 */
public class UserTest {
    public static void main(String[] args) {
        User a = new User(1, "a", 21);
        User b = new User(2, "b", 22);
        User c = new User(3, "c", 23);
        User d = new User(4, "d", 24);
        User e = new User(5, "e", 25);
        User f = new User(6, "F", 25);

        // 集合就是存储,计算交给Stream流
        List<User> users = Arrays.asList(a, b, c, d, e,f);

        // 链式编程  // 集合就是存储,计算交给Stream流
        users.stream().
                 filter(user -> {return user.getId()%2==0;})  // 偶数
                .filter(user -> {return user.getAge()>23;})   // 大于23岁
                .map(user -> {return user.getName().toUpperCase();})
                .sorted((u1,u2)->{return -u1.compareTo(u2);})
                .limit(1)
                .forEach(System.out::println);
    }
}
